#!/bin/bash

set -x
set -e

echo -e ${JIANMU_HOSTS} >> /etc/hosts

cat /etc/hosts

mkdir -p ${JIANMU_WORKSPACE}
chmod +x ${JIANMU_WORKSPACE}
cd ${JIANMU_WORKSPACE}

pwd

cmd="${JIANMU_CMD} --out-dir ${JIANMU_WORKSPACE}"

if [[ -n ${JIANMU_COUNT} ]]; then
  cmd="${cmd} -n ${JIANMU_COUNT}"
fi

if [[ -n ${JIANMU_DB_CONNECTION_CONFIG} ]]; then
  echo ${JIANMU_DB_CONNECTION_CONFIG} > ./db.config
  cmd="${cmd} --database-connection ./db.config"
fi

if [[ ${JIANMU_UPLOAD_REPORTER} ]]; then
    cmd="${cmd} --upload-report"
fi


echo -e "{
    "\"result_dir\"" ":" "\"${JIANMU_WORKSPACE}/apifox-reports\""
}" > /usr/resultFile

  echo "resultFile:"
cat /usr/resultFile

ls -l ${JIANMU_WORKSPACE}
eval "$cmd"